package self.zhangkang.chart.view.kline.index

import android.graphics.Canvas
import android.graphics.Paint
import self.zhangkang.chart.data.KLineInfo
import self.zhangkang.chart.tools.CanvasTools
import self.zhangkang.chart.view.IndexNameConfig
import self.zhangkang.chart.view.kline.KLineIndex
import self.zhangkang.chart.view.kline.KLineIndexInfo
import self.zhangkang.chart.view.kline.KLineViewColor
import self.zhangkang.chart.view.kline.KLineViewDimen
import self.zhangkang.chart.view.pool.PathPool
import self.zhangkang.chart.view.pool.RectPool

/**
 * @author : Android-张康
 * created on: 2023/5/9 18:19
 * description: 未知
 */
internal class KLineUnknown(
    private val pathPool: PathPool,
    private val rectPool: RectPool,
    private val kLineViewColor: KLineViewColor,
    private val kLineViewDimen: KLineViewDimen,
    private val indexNameConfig: IndexNameConfig
) : KLineIndexInfo {


    /**
     * 是否可以切换
     *
     * @return true 可以切换，false 不可以切换
     */
    override fun canSwitch(): Boolean {
        return getIndexInfo().canSwitch
    }

    /**
     * 是否点击到名称
     *
     * @param startX 开始X
     * @param startY 开始Y
     * @param stopX 结束X
     * @param stopY 结束Y
     * @param touchX 触摸的 X
     * @param touchY 触摸的 Y
     * @param textPaint 文字的画笔
     *
     * @return true 是，false 否
     */
    override fun isClickInName(
        startX: Float,
        startY: Float,
        stopX: Float,
        stopY: Float,
        touchX: Float,
        touchY: Float,
        textPaint: Paint
    ): Boolean {
        val textBoundsRect = rectPool.acquire()
        //先绘制指标名称
        CanvasTools.getDrawTextBounds(
            startX = startX,
            startY = startY,
            stopY = stopY,
            textPaint = textPaint,
            indicatorName = KLineIndex.KLine.indexName,
            indexNameConfig = indexNameConfig,
            textBoundsRect = textBoundsRect,
            hasArrowDropDown = canSwitch(),
        )
        val contains = textBoundsRect.contains(touchX.toInt(), touchY.toInt())
        rectPool.release(textBoundsRect)
        return contains
    }

    /**
     * 获取指标类型
     */
    override fun getIndexInfo(): KLineIndex {
        return KLineIndex.Volume
    }

    override fun getProportion(): Int {
        return 15
    }

    /**
     * 计算最大值前
     *
     * @param kLineInfo 第一个值
     */
    override fun calculationMaxAndMinBefore(kLineInfo: KLineInfo) {

    }

    /**
     * 计算最大值
     *
     * @param kLineInfo 当前值
     */
    override fun calculationMaxAndMin(kLineInfo: KLineInfo) {

    }

    /**
     * 计算最大值后
     */
    override fun calculationMaxAndMinAfter() {

    }

    /**
     * 绘制背景
     *
     * @param canvas 画布
     * @param startX 开始X
     * @param startY 开始Y
     * @param stopX 结束X
     * @param stopY 结束Y
     * @param paint 画布
     */
    override fun drawBackground(
        canvas: Canvas,
        startX: Float,
        startY: Float,
        stopX: Float,
        stopY: Float,
        linePaint: Paint,
        textPaint: Paint
    ) {
        val backgroundPath = pathPool.acquire().apply {
            moveTo(startX, startY)
            lineTo(stopX, startY)
            lineTo(stopX, stopY)
            lineTo(startX, stopY)
            close()
        }
        canvas.drawPath(backgroundPath, linePaint)
        pathPool.release(backgroundPath)
    }

    override fun drawCurrentIndexInfo(
        canvas: Canvas,
        startX: Float,
        startY: Float,
        stopX: Float,
        stopY: Float,
        linePaint: Paint,
        textPaint: Paint,
        marginTop: Float,
        span: Int,
        indexValueHorizontalSpace: Float,
        indexValueVerticalSpace: Float,
        kLineInfo: KLineInfo,
        kLineIsLine: Boolean
    ) {
        //先绘制指标名称
        CanvasTools.drawIndicatorName(
            canvas = canvas,
            startX = startX,
            startY = startY,
            stopY = stopY,
            linePaint = linePaint,
            textPaint = textPaint,
            rectPool = rectPool,
            indicatorName = KLineIndex.Volume.indexName,
            indexNameConfig = indexNameConfig,
            hasArrowDropDown = canSwitch()
        )
    }

    override fun beforeDrawItemContent(
        canvas: Canvas,
        startX: Float,
        startY: Float,
        stopX: Float,
        stopY: Float,
        paint: Paint,
        candlestickWidth: Float,
        candlestickWidthSpace: Float,
        kLineInfo: KLineInfo,
        kLineIsLine: Boolean
    ) {

    }

    override fun drawItemContent(
        canvas: Canvas,
        startX: Float,
        startY: Float,
        stopX: Float,
        stopY: Float,
        textPaint: Paint,
        linePaint: Paint,
        kLineInfo: KLineInfo,
        isFirst: Boolean,
        yangLineIsFill: Boolean,
        totalTranslateX: Float,
        candlestickWidth: Float,
        halfCandlestickWidth: Float,
        kLineIsLine: Boolean
    ) {

    }

    override fun afterDrawItemContent(canvas: Canvas, paint: Paint) {

    }

    /**
     * 获取当前左边的值
     *
     * @param percentage 比例
     *
     * @return 返回当前左边坐标的值
     */
    override fun getCurrentLeftValue(percentage: Float): String? {
        return null
    }

    /**
     * 获取当前右边的值
     *
     * @param percentage 比例
     *
     * @return 返回当前右边坐标的值
     */
    override fun getCurrentRightValue(percentage: Float): String? {
        return null
    }
}